package map.android.baidu.carpool.reservation;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import map.android.baidu.carpool.widget.wheel.AbstractWheelTextAdapter;

/**
 * Numeric Wheel adapter.
 */
public class HoursWheelAdapter extends AbstractWheelTextAdapter {
	private List<Integer> mHoursList = new ArrayList<Integer>();

	public void setData(List<Integer> hoursList) {
		mHoursList = hoursList;
		notifyDataInvalidatedEvent();
	}

	public List<Integer> getData() {
		return mHoursList;
	}

	/**
	 * Constructor
	 * 
	 * @param context
	 *            the current context
	 */
	public HoursWheelAdapter(Context context) {
		super(context);
	}

	/**
	 * Constructor
	 * 
	 * @param context
	 *            the current context
	 * @param minValue
	 *            the wheel min value
	 * @param maxValue
	 *            the wheel max value
	 */
	public HoursWheelAdapter(Context context, int minValue, int maxValue) {
		this(context, minValue, maxValue, null);
	}

	public HoursWheelAdapter(Context context, int minValue, int maxValue,
			String format) {
		super(context);
	}

	public int getItemValue(int index) {
		if (index >= 0 && index < getItemsCount()) {
			Integer integer = mHoursList.get(index);
			int value = integer.intValue();
			return value;
		}
		return 0;
	}

	@Override
	public CharSequence getItemText(int index) {
		int value = getItemValue(index);
		if (value == Integer.MAX_VALUE) {
			return "";
		}
		String str = intToString(value);
		return str;
	}

	private String intToString(int i) {
		String str = i < 10 ? "0" + i : "" + i;
		return str;
	}

	@Override
	public int getItemsCount() {
		if (mHoursList == null) {
			return 0;
		}
		return mHoursList.size();
	}
}
